home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume19 / fbm / part02 < prev    next >
Encoding:
Internet Message Format  |  1989-06-08  |  57.8 KB

  1. Subject:  v19i048:  FBM, image manipulation library, Part02/08
  2. Newsgroups: comp.sources.unix
  3. Sender: sources
  4. Approved: rsalz@uunet.UU.NET
  5.  
  6. Submitted-by: Michael.Mauldin@NL.CS.CMU.EDU
  7. Posting-number: Volume 19, Issue 48
  8. Archive-name: fbm/part02
  9.  
  10. #! /bin/sh
  11. # This is a shell archive.  Remove anything before this line, then unpack
  12. # it by saving it into a file and typing "sh file".  To overwrite existing
  13. # files, type "sh file -c".  You can also feed this as standard input via
  14. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  15. # will see the following message at the end:
  16. #        "End of archive 2 (of 8)."
  17. # Contents:  clr2gray.c fbcat.1 fbcat.c fbclean.c fbedge.c fbext.1
  18. #   fbhist.c fbinfo.c fbmask.c fbquant.1 fbrot.c fbsample.1 fbsharp.c
  19. #   flcavg.c flthre.c flwrfb.c gray2clr.c qrt2fbm.c
  20. # Wrapped by rsalz@fig.bbn.com on Fri Jun  9 08:38:21 1989
  21. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  22. if test -f 'clr2gray.c' -a "${1}" != "-c" ; then 
  23.   echo shar: Will not clobber existing file \"'clr2gray.c'\"
  24. else
  25. echo shar: Extracting \"'clr2gray.c'\" \(2601 characters\)
  26. sed "s/^X//" >'clr2gray.c' <<'END_OF_FILE'
  27. X/*****************************************************************
  28. X * clr2gray.c: FBM Library 0.9 (Beta test) 07-Mar-89  Michael Mauldin
  29. X *
  30. X * Copyright (C) 1989 by Michael Mauldin.  Permission is granted to
  31. X * use this file in whole or in part provided that you do not sell it
  32. X * for profit and that this copyright notice is retained unchanged.
  33. X *
  34. X * USAGE
  35. X *    % clr2gray [ -r<red> -g<grn> -b<blu> ] [ -<type> ] < color > gray
  36. X *
  37. X * EDITLOG
  38. X *    LastEditDate = Tue Mar  7 19:56:03 1989 - Michael Mauldin
  39. X *    LastFileName = /usr2/mlm/src/misc/fbm/clr2gray.c
  40. X *
  41. X * HISTORY
  42. X * 07-Mar-89  Michael Mauldin (mlm) at Carnegie Mellon University
  43. X *    Beta release (version 0.9) mlm@cs.cmu.edu
  44. X *
  45. X * 06-Mar-89  Michael Mauldin (mlm) at Carnegie Mellon University
  46. X *    Added options for RGB weights
  47. X *
  48. X *  1-Dec-88  Michael Mauldin (mlm) at Carnegie-Mellon University
  49. X *    Created.
  50. X *****************************************************************/
  51. X
  52. X# include <stdio.h>
  53. X# include <math.h>
  54. X# include "fbm.h"
  55. X
  56. X# define USAGE \
  57. X"Usage: clr2gray [ -r<red> -g<grn> -b<blu> ] [ -<type> ] < color > gray"
  58. X
  59. X#ifndef lint
  60. Xstatic char *fbmid =
  61. X    "$FBM clr2gray.c <0.9> 07-Mar-89  (C) 1989 by Michael Mauldin$";
  62. X#endif
  63. X
  64. Xmain (argc, argv)
  65. Xchar *argv[];
  66. X{ FBM input, output;
  67. X  int outtype = DEF_8BIT;
  68. X  int rw=0, gw=0, bw=0;
  69. X
  70. X  /* Get the options */
  71. X  while (--argc > 0 && (*++argv)[0] == '-')
  72. X  { while (*++(*argv))
  73. X    { switch (**argv)
  74. X      { 
  75. X    case 'r':    rw = atoi (*argv+1); SKIPARG; break;
  76. X    case 'g':    gw = atoi (*argv+1); SKIPARG; break;
  77. X    case 'b':    bw = atoi (*argv+1); SKIPARG; break;
  78. X    case 'A':    outtype = FMT_ATK; break;
  79. X    case 'B':    outtype = FMT_FACE; break;
  80. X    case 'F':    outtype = FMT_FBM; break;
  81. X    case 'G':    outtype = FMT_GIF; break;
  82. X    case 'I':    outtype = FMT_IFF; break;
  83. X    case 'L':    outtype = FMT_LEAF; break;
  84. X    case 'M':    outtype = FMT_MCP; break;
  85. X    case 'P':    outtype = FMT_PBM; break;
  86. X    case 'S':    outtype = FMT_SUN; break;
  87. X    case 'T':    outtype = FMT_TIFF; break;
  88. X    case 'X':    outtype = FMT_X11; break;
  89. X    case 'Z':    outtype = FMT_PCX; break;
  90. X    default:        fprintf (stderr, "%s\n", USAGE);
  91. X                        exit (1);
  92. X      }
  93. X    }
  94. X  }
  95. X
  96. X  /* Use NTSC weights for defaults */
  97. X  if (rw + gw + bw <= 0)
  98. X  { rw = 299; gw = 587; bw = 114; }
  99. X
  100. X  /* Clear the memory pointers so alloc_fbm won't be confused */
  101. X  input.cm  = input.bm  = (unsigned char *) NULL;
  102. X  output.cm = output.bm = (unsigned char *) NULL;
  103. X
  104. X  /* Read the image and convert it, use NTSC weights */
  105. X  if (read_bitmap (&input, (char *) NULL) &&
  106. X      clr2gray (&input, &output, rw, gw, bw) &&
  107. X      write_bitmap (&output, stdout, outtype))
  108. X  { exit (0); }
  109. X
  110. X  exit (1);
  111. X}
  112. END_OF_FILE
  113. if test 2601 -ne `wc -c <'clr2gray.c'`; then
  114.     echo shar: \"'clr2gray.c'\" unpacked with wrong size!
  115. fi
  116. # end of 'clr2gray.c'
  117. fi
  118. if test -f 'fbcat.1' -a "${1}" != "-c" ; then 
  119.   echo shar: Will not clobber existing file \"'fbcat.1'\"
  120. else
  121. echo shar: Extracting \"'fbcat.1'\" \(2241 characters\)
  122. sed "s/^X//" >'fbcat.1' <<'END_OF_FILE'
  123. X.TH FBCAT 1 07-Mar-89
  124. X.CM 3
  125. X.SH NAME
  126. Xfbcat \- convert image format
  127. X.SH SYNOPSIS
  128. X.nf
  129. Xfbcat [ -a<aspect> -t'title' -c'credits' ] [ -<type> ] [ image ] > image
  130. X.fi
  131. X.SH DESCRIPTION
  132. X.PP
  133. XA general format converter.  It can read any of the known formats
  134. Xand write one of the specified output formats (see fbm(1) for format
  135. Xdetails).  Note that some conversions require more than simple format
  136. Xchanges, such as color to grayscale or grayscale to 1bit.  For these
  137. Xconversion you must use a pipeline of ther commands.
  138. X.SH OPTIONS
  139. X.TP
  140. X.BR -a<aspect>
  141. X.I aspect ratio,
  142. Xa floating point number which is the ratio of the height of a pixel to
  143. Xits width.  Some formats specify this, and for GIF images the reader
  144. Xattempts to guess from the size of the image.  This option overrides
  145. Xthe input or guessed aspect ratio.  So if you know that your GIF image
  146. Xhas a 1-1 aspect ratio, you should specify -a1 to override the guess.
  147. X.TP
  148. X.BR -t'title'
  149. X.I title,
  150. Xspecify a character string (up to 80 characters) to describe the image.
  151. XThe default is no title.
  152. X.TP
  153. X.BR -c'credits'
  154. X.I credits or subtitle,
  155. Xspecify a second character string (up to 80 characters) to describe the
  156. Ximage.  The default is no credit string.
  157. X.TP
  158. X.BR -B
  159. X.I face
  160. Xformat, as used by Bennet Yee's
  161. X.I face
  162. Xprogram at CMU. 
  163. X.TP
  164. X.BR -F
  165. X.I FBM,
  166. Xformat (by default, the default).  You are guaranteed not
  167. Xto lose information by specifying FBM as the default.
  168. X.TP
  169. X.BR -G
  170. X.I GIF,
  171. XCompuserve GIF format.
  172. X.TP
  173. X.BR -I
  174. X.I IFF
  175. Xformat, interleaved bitmaps (ILBM), used by Amigas.
  176. X.TP
  177. X.BR -P
  178. X.I PBM,
  179. XJef Poskanzer's bitmap format.
  180. X.TP
  181. X.BR -S
  182. X.I sun,
  183. XSun rasterfiles (not run length encoded).
  184. X.SH EXAMPLE
  185. X.PP
  186. XTo convert a GIF file to an IFF file
  187. X.sp
  188. X    % fbcat -I < foo.gif > foo.iff
  189. X.sp
  190. XTo convert a Sun raster file to an FBM file, adding a title:
  191. X.sp
  192. X    % fbcat -t'Title String' < bar.8bit > bar.fbm
  193. X.SH SEE ALSO
  194. Xfbm(1) for general discussion, pbm(1) for PBM routines.
  195. X.SH BUGS
  196. XNone known.
  197. X.SH HISTORY
  198. XCopyright (c) 1989 by Michael L. Mauldin.  
  199. XPermission is granted to use this program in whole or in part provided
  200. Xthat you do not sell it for profit and that this copyright notice is
  201. Xretained unchanged.
  202. X.TP
  203. X07-Mar-89  Michael L. Mauldin at Carnegie Mellon University
  204. XBeta release (version 0.9) mlm@cs.cmu.edu
  205. END_OF_FILE
  206. if test 2241 -ne `wc -c <'fbcat.1'`; then
  207.     echo shar: \"'fbcat.1'\" unpacked with wrong size!
  208. fi
  209. # end of 'fbcat.1'
  210. fi
  211. if test -f 'fbcat.c' -a "${1}" != "-c" ; then 
  212.   echo shar: Will not clobber existing file \"'fbcat.c'\"
  213. else
  214. echo shar: Extracting \"'fbcat.c'\" \(3257 characters\)
  215. sed "s/^X//" >'fbcat.c' <<'END_OF_FILE'
  216. X/*****************************************************************
  217. X * fbcat.c: FBM Library 0.9 (Beta test) 07-Mar-89  Michael Mauldin
  218. X *
  219. X * Copyright (C) 1989 by Michael Mauldin.  Permission is granted to
  220. X * use this file in whole or in part provided that you do not sell it
  221. X * for profit and that this copyright notice is retained unchanged.
  222. X *
  223. X * fbcat.c: 
  224. X *    Convert an image from one format to another.  Input image type
  225. X *    is determined by magic number.  Output is specified by argument.
  226. X *    Note that the ascpect ratio, size and number of colors is not
  227. X *    changed, and that some conversions (such as grayscale to bitmap
  228. X *    or color to gray require more processing than fbcat can do.
  229. X *    For these transformations you must use other programs like
  230. X *    clr2gray, gray2clr, fbhalf, and fbsample.
  231. X *
  232. X * USAGE
  233. X *    % fbcat [ -t'title' -c'credits' ] [ -<type> ] [ image ] > image
  234. X *
  235. X * EDITLOG
  236. X *    LastEditDate = Wed May  3 22:03:33 1989 - Michael Mauldin
  237. X *    LastFileName = /usr2/mlm/src/misc/fbm/fbcat.c
  238. X *
  239. X * HISTORY
  240. X * 07-Mar-89  Michael Mauldin (mlm) at Carnegie Mellon University
  241. X *    Beta release (version 0.9) mlm@cs.cmu.edu
  242. X *
  243. X * 29-Nov-88  Michael Mauldin (mlm) at Carnegie-Mellon University
  244. X *    Created.
  245. X *****************************************************************/
  246. X
  247. X
  248. X# include <stdio.h>
  249. X# include "fbm.h"
  250. X
  251. X# define USAGE \
  252. X"Usage: fbcat [ -a<aspect> -t'title' -c'credits' ]\n\
  253. X         [ -<type> ] [ image ] > image"
  254. X
  255. X/****************************************************************
  256. X * main
  257. X ****************************************************************/
  258. X
  259. X#ifndef lint
  260. Xstatic char *fbmid =
  261. X    "$FBM fbcat.c <0.9> 07-Mar-89  (C) 1989 by Michael Mauldin$";
  262. X#endif
  263. X
  264. Xmain (argc, argv)
  265. Xchar *argv[];
  266. X{ FBM image;
  267. X  int outtype = FMT_FBM;
  268. X  double aspect = 0.0;
  269. X  char *title = NULL, *credits = NULL;
  270. X
  271. X  /* Get the options */
  272. X  while (--argc > 0 && (*++argv)[0] == '-')
  273. X  { while (*++(*argv))
  274. X    { switch (**argv)
  275. X      {
  276. X    case 'a':    aspect = atof (*argv+1); SKIPARG; break;
  277. X    case 't':    title = *argv+1; SKIPARG; break;
  278. X    case 'c':    credits = *argv+1; SKIPARG; break;
  279. X    case 'A':    outtype = FMT_ATK; break;
  280. X    case 'B':    outtype = FMT_FACE; break;
  281. X    case 'F':    outtype = FMT_FBM; break;
  282. X    case 'G':    outtype = FMT_GIF; break;
  283. X    case 'I':    outtype = FMT_IFF; break;
  284. X    case 'M':    outtype = FMT_MCP; break;
  285. X    case 'P':    outtype = FMT_PBM; break;
  286. X    case 'S':    outtype = FMT_SUN; break;
  287. X    case 'T':    outtype = FMT_TIFF; break;
  288. X    case 'X':    outtype = FMT_X11; break;
  289. X    case 'Z':    outtype = FMT_PCX; break;
  290. X    default:        fprintf (stderr, "%s\n", USAGE);
  291. X                        exit (1);
  292. X      }
  293. X    }
  294. X  }
  295. X
  296. X  /* Clear the memory pointers so alloc_fbm won't be confused */
  297. X  image.cm  = image.bm  = (unsigned char *) NULL;
  298. X
  299. X  /* Now read in the Sun format image and write an FBM format file */
  300. X  if (read_bitmap (&image, (argc > 0) ? *argv : (char *) NULL))
  301. X  {
  302. X    if (aspect != 0.0)
  303. X    { fprintf (stderr,
  304. X           "Overiding aspect ratio read (%1.3lf) with (%1.3lf)\n",
  305. X           image.hdr.aspect, aspect);
  306. X      image.hdr.aspect = aspect;
  307. X    }
  308. X
  309. X    if (title)
  310. X    { strncpy (image.hdr.title, title, FBM_MAX_TITLE); }
  311. X
  312. X    if (credits)
  313. X    { strncpy (image.hdr.credits, credits, FBM_MAX_TITLE); }
  314. X
  315. X    if (write_bitmap (&image, stdout, outtype))
  316. X    { exit (0);
  317. X    }
  318. X  }
  319. X
  320. X  exit (1);
  321. X}
  322. END_OF_FILE
  323. if test 3257 -ne `wc -c <'fbcat.c'`; then
  324.     echo shar: \"'fbcat.c'\" unpacked with wrong size!
  325. fi
  326. # end of 'fbcat.c'
  327. fi
  328. if test -f 'fbclean.c' -a "${1}" != "-c" ; then 
  329.   echo shar: Will not clobber existing file \"'fbclean.c'\"
  330. else
  331. echo shar: Extracting \"'fbclean.c'\" \(3425 characters\)
  332. sed "s/^X//" >'fbclean.c' <<'END_OF_FILE'
  333. X/*****************************************************************
  334. X * fbclean.c: FBM Library 0.9 (Beta test) 07-Mar-89  Michael Mauldin
  335. X *
  336. X * Copyright (C) 1989 by Michael Mauldin & Gary Sherwin.
  337. X * Permission is granted to use this file in whole or in part provided
  338. X * that you do not sell it for profit and that this copyright notice
  339. X * is retained unchanged.
  340. X *
  341. X * fbclean.c: Normalize contrast and brightness of image
  342. X *
  343. X * USAGE
  344. X *      % fbclean [ flag ] < image > image2
  345. X *
  346. X * EDITLOG
  347. X *    New Filename = fbclean.c  Mon Nov 7 09:24:00 1988 - Gary Sherwin
  348. X *    LastEditDate = Mon Oct 31 08:34:55 1988 - Michael Mauldin
  349. X *    LastFileName = /usr2/mlm/src/misc/images/bsharp.c
  350. X *      LastEditDate = Tue Mar  7 17:46:17 1989 - Michael Mauldin
  351. X *      LastFileName = /usr2/mlm/src/misc/fbm/fbclean.c
  352. X *
  353. X * HISTORY
  354. X * 07-Mar-89  Michael Mauldin (mlm) at Carnegie Mellon University
  355. X *    Beta release (version 0.9) mlm@cs.cmu.edu
  356. X *
  357. X * 07-Nov-88  Gary W. Sherwin (sherwin) at Westinghouse R&D
  358. X *    Changed to fbclean.
  359. X *
  360. X * 10-Sep-88  Michael Mauldin (mlm) at Carnegie-Mellon University
  361. X *    Created.
  362. X *****************************************************************/
  363. X
  364. X# include <stdio.h>
  365. X# include <math.h>
  366. X# include "fbm.h"
  367. X
  368. X# define USAGE \
  369. X  "Usage: fbclean [ -b<cleaner> -t<threshhold> -n<nbr> ]\n\
  370. X           [ -<type> ] < bitmap > bitmap"
  371. X
  372. X#ifndef lint
  373. Xstatic char *fbmid =
  374. X    "$FBM fbclean.c <0.9> 07-Mar-89  (C) 1989 by Michael Mauldin$";
  375. X#endif
  376. X
  377. Xmain (argc, argv)
  378. Xchar *argv[];
  379. X{ int w, h, k;
  380. X  int cleaner = 5;
  381. X  int blacktrp = 0;
  382. X  int nbr = 5;
  383. X  int outtype = DEF_1BIT;
  384. X  FBM input, output;
  385. X
  386. X  /* Get the options */
  387. X  while (--argc > 0 && (*++argv)[0] == '-')
  388. X  { while (*++(*argv))
  389. X    { switch (**argv)
  390. X      { case 'b':       cleaner = atoi (*argv+1); SKIPARG; break;
  391. X        case 't':    blacktrp = atoi (*argv+1); SKIPARG; break;
  392. X        case 'n':    nbr = atoi (*argv+1); SKIPARG; break;
  393. X    case 'A':    outtype = FMT_ATK; break;
  394. X    case 'B':    outtype = FMT_FACE; break;
  395. X    case 'F':    outtype = FMT_FBM; break;
  396. X    case 'G':    outtype = FMT_GIF; break;
  397. X    case 'I':    outtype = FMT_IFF; break;
  398. X    case 'L':    outtype = FMT_LEAF; break;
  399. X    case 'M':    outtype = FMT_MCP; break;
  400. X    case 'P':    outtype = FMT_PBM; break;
  401. X    case 'S':    outtype = FMT_SUN; break;
  402. X    case 'T':    outtype = FMT_TIFF; break;
  403. X    case 'X':    outtype = FMT_X11; break;
  404. X    case 'Z':    outtype = FMT_PCX; break;
  405. X        default:        fprintf (stderr, "%s\n", USAGE);
  406. X                        exit (1);
  407. X      }
  408. X    }
  409. X  }
  410. X  
  411. X  /* Clear the memory pointers so alloc_fbm won't be confused */
  412. X  input.cm  = input.bm  = (unsigned char *) NULL;
  413. X  output.cm = output.bm = (unsigned char *) NULL;
  414. X
  415. X  /* Read the image and clean it */
  416. X  if (read_bitmap (&input, (char *) NULL))
  417. X  {
  418. X    if (input.hdr.bits != 8 || input.hdr.physbits != 8)
  419. X    { fprintf (stderr,
  420. X           "Can't handle images with %d bits and %d physbits per pixel\n",
  421. X           input.hdr.bits, input.hdr.physbits);
  422. X      exit (1);
  423. X    }
  424. X
  425. X    /* Determine output height & width (oh*ow <= size) */
  426. X    h = input.hdr.rows;
  427. X    w = input.hdr.cols;
  428. X    k = input.hdr.planes;
  429. X
  430. X    fprintf (stderr,
  431. X         "Cleaning \"%s\", # of Neighbors %2d, nbr %d [%dx%dx%d]\n",
  432. X         input.hdr.title[0] ? input.hdr.title : "(untitled)",
  433. X         cleaner, nbr, w, h, k);
  434. X
  435. X    /* Clean the image using a digitial Laplacian */
  436. X    if (clean_fbm (&input, &output, cleaner, blacktrp, nbr) &&
  437. X        write_bitmap (&output, stdout, outtype))
  438. X    { exit (0); }
  439. X  }
  440. X  
  441. X  exit (1);
  442. X}
  443. END_OF_FILE
  444. if test 3425 -ne `wc -c <'fbclean.c'`; then
  445.     echo shar: \"'fbclean.c'\" unpacked with wrong size!
  446. fi
  447. # end of 'fbclean.c'
  448. fi
  449. if test -f 'fbedge.c' -a "${1}" != "-c" ; then 
  450.   echo shar: Will not clobber existing file \"'fbedge.c'\"
  451. else
  452. echo shar: Extracting \"'fbedge.c'\" \(3190 characters\)
  453. sed "s/^X//" >'fbedge.c' <<'END_OF_FILE'
  454. X/*****************************************************************
  455. X * fbedge.c: FBM Library 0.9 (Beta test) 07-Mar-89  Michael Mauldin
  456. X *
  457. X * Copyright (C) 1989 by Michael Mauldin & Gary Sherwin.
  458. X * Permission is granted to use this file in whole or in part provided
  459. X * that you do not sell it for profit and that this copyright notice
  460. X * is retained unchanged.
  461. X *
  462. X * fbedge.c: Take derivative and edge detect image
  463. X *
  464. X * USAGE
  465. X *      % fbedge [ flag ] < image > image2
  466. X *
  467. X * EDITLOG
  468. X *    New Filename = fbedge.c  Mon Nov 7 09:24:00 1988 - Gary Sherwin
  469. X *    LastEditDate = Mon Oct 31 08:34:55 1988 - Michael Mauldin
  470. X *    LastFileName = /usr2/mlm/src/misc/images/bsharp.c
  471. X *      LastEditDate = Tue Mar  7 17:50:04 1989 - Michael Mauldin
  472. X *      LastFileName = /usr2/mlm/src/misc/fbm/fbedge.c
  473. X *
  474. X * HISTORY
  475. X * 07-Mar-89  Michael Mauldin (mlm) at Carnegie Mellon University
  476. X *    Beta release (version 0.9) mlm@cs.cmu.edu
  477. X *
  478. X * 07-Nov-88  Gary W. Sherwin (sherwin) at Westinghouse R&D
  479. X *    Changed to fbedge.
  480. X *
  481. X * 10-Sep-88  Michael Mauldin (mlm) at Carnegie-Mellon University
  482. X *    Created.
  483. X *****************************************************************/
  484. X
  485. X# include <stdio.h>
  486. X# include <math.h>
  487. X# include "fbm.h"
  488. X
  489. X# define USAGE "Usage: fbedge [ -t<threshhold> ] < bitmap > bitmap"
  490. X
  491. X#ifndef lint
  492. Xstatic char *fbmid =
  493. X    "$FBM fbedge.c <0.9> 07-Mar-89  (C) 1989 by Michael Mauldin$";
  494. X#endif
  495. X
  496. Xmain (argc, argv)
  497. Xchar *argv[];
  498. X{ int w, h, k;
  499. X  int blacktrp = 0;
  500. X  int outtype = DEF_1BIT;
  501. X  FBM input, output;
  502. X
  503. X  /* Get the options */
  504. X  while (--argc > 0 && (*++argv)[0] == '-')
  505. X  { while (*++(*argv))
  506. X    { switch (**argv)
  507. X      { case 't':    blacktrp = atoi (*argv+1); SKIPARG; break;
  508. X    case 'A':    outtype = FMT_ATK; break;
  509. X    case 'B':    outtype = FMT_FACE; break;
  510. X    case 'F':    outtype = FMT_FBM; break;
  511. X    case 'G':    outtype = FMT_GIF; break;
  512. X    case 'I':    outtype = FMT_IFF; break;
  513. X    case 'L':    outtype = FMT_LEAF; break;
  514. X    case 'M':    outtype = FMT_MCP; break;
  515. X    case 'P':    outtype = FMT_PBM; break;
  516. X    case 'S':    outtype = FMT_SUN; break;
  517. X    case 'T':    outtype = FMT_TIFF; break;
  518. X    case 'X':    outtype = FMT_X11; break;
  519. X    case 'Z':    outtype = FMT_PCX; break;
  520. X        default:        fprintf (stderr, "%s\n", USAGE);
  521. X                        exit (1);
  522. X      }
  523. X    }
  524. X  }
  525. X  
  526. X  /* Clear the memory pointers so alloc_fbm won't be confused */
  527. X  input.cm  = input.bm  = (unsigned char *) NULL;
  528. X  output.cm = output.bm = (unsigned char *) NULL;
  529. X
  530. X  /* Read the image and clean it */
  531. X  if (read_bitmap (&input, (char *) NULL))
  532. X  {
  533. X    if (input.hdr.bits != 8 || input.hdr.physbits != 8)
  534. X    { fprintf (stderr,
  535. X           "Can't handle images with %d bits and %d physbits per pixel\n",
  536. X           input.hdr.bits, input.hdr.physbits);
  537. X      exit (1);
  538. X    }
  539. X
  540. X    /* Determine output height & width (oh*ow <= size) */
  541. X    h = input.hdr.rows;
  542. X    w = input.hdr.cols;
  543. X    k = input.hdr.planes;
  544. X
  545. X    fprintf (stderr,
  546. X         "Edge detect\"%s\", Black-trip %2d [%dx%dx%d]\n",
  547. X         input.hdr.title[0] ? input.hdr.title : "(untitled)",
  548. X         blacktrp, w, h, k);
  549. X
  550. X    /* Edge detect the image using a digitial Laplacian */
  551. X    if (findedge_fbm (&input, &output, blacktrp) &&
  552. X        write_bitmap (&output, stdout, outtype))
  553. X    { exit (0); }
  554. X  }
  555. X  
  556. X  exit (1);
  557. X}
  558. END_OF_FILE
  559. if test 3190 -ne `wc -c <'fbedge.c'`; then
  560.     echo shar: \"'fbedge.c'\" unpacked with wrong size!
  561. fi
  562. # end of 'fbedge.c'
  563. fi
  564. if test -f 'fbext.1' -a "${1}" != "-c" ; then 
  565.   echo shar: Will not clobber existing file \"'fbext.1'\"
  566. else
  567. echo shar: Extracting \"'fbext.1'\" \(2772 characters\)
  568. sed "s/^X//" >'fbext.1' <<'END_OF_FILE'
  569. X.TH FBEXT 1 07-Mar-89
  570. X.CM 3
  571. X.SH NAME
  572. Xfbext \- extract a rectangle from an image, resize, change aspect ratio
  573. X.SH SYNOPSIS
  574. X.nf
  575. Xfbext [ -w<width> -h<height> -W<maxwdith> -H<maxheight>
  576. X        -s<size> -a<aspect> -t'title' -c'credits' ] [ -<type> ]
  577. X        [ x y [ width height ] ]     < bitmap > bitmap
  578. X.fi
  579. X.SH DESCRIPTION
  580. X.PP
  581. XExtract a rectangle from a bitmap and resize it.  There are lots of
  582. Xarguments, but you'll typically only give it a few.  For example, you
  583. Xshould only specify two of width, height and aspect ratio, and it will
  584. Xcalculate the third.  The rectangle spec is given as 2 or 4 positional
  585. Xarguments after the flags, and if omitted the entire input image is
  586. Xcopied.
  587. X.sp
  588. XThe maximum width and height override all other size specifications, so
  589. Xthey can be used ot keep the results displayable on your screen.
  590. X.sp
  591. XWhen working with Amiga images, remember that the original input has an
  592. Xaspect ratio of 1.2, so a common operation is "fbext -a1" which expands
  593. Xthe smaller dimension to give an output with an aspect ratio of 1.
  594. X.SH OPTIONS
  595. X.TP
  596. X.B -SPFB
  597. X.I output file format,
  598. XS=sun, P=pbm, F=fbm, B=face format.  Only one may be specified.
  599. X.TP
  600. X.B -a
  601. X.I aspect ratio,
  602. Xspecify desired output aspect ratio.
  603. X.TP
  604. X.B -w
  605. X.I width,
  606. Xspecify desired output width in pixels.
  607. X.TP
  608. X.B -h
  609. X.I height,
  610. Xspecify desired output height in pixels.
  611. X.TP
  612. X.B -s
  613. X.I size,
  614. Xspecify desired number of pixels in output (eg: 320x200 is 64000 pixels.
  615. X.TP
  616. X.B -W
  617. X.I maximum width,
  618. Xof output.  The image will be expanded up to this size, keeping the
  619. Xspecified aspect ratio.
  620. X.TP
  621. X.B -H
  622. X.I maximum height.,
  623. X.TP
  624. X.BR -t'title'
  625. X.I title,
  626. Xspecify a character string (up to 80 characters) to describe the image.
  627. XThe default is no title.
  628. X.TP
  629. X.BR -c'credits'
  630. X.I credits or subtitle,
  631. Xspecify a second character string (up to 80 characters) to describe the
  632. Ximage.  The default is no credit string.
  633. X.PP
  634. X.SH EXAMPLE
  635. X.PP
  636. XSuppose you have a GIF file with 320 by 200 pixels and an aspect ratio
  637. Xof 1.2 (that is, it looks right at 320 by 240 pixels).  You want to
  638. Xblow it up to fit your Sun screen (1152 by 900). You want the output
  639. Xratio adjusted to be 1.0 so it will look right on the Sun.
  640. X.sp
  641. Xfbext -S -W1152 -H900 -a1.0 < foo.gif > foo.raster
  642. X.sp
  643. XYou have an FBM format file 512 by 384 and you want to extract a
  644. Xrectangle 300 by 200 from the middle:
  645. X.sp
  646. Xfbext -F 106 92 300 200 < foo.fbm > bar.fbm
  647. X.sp
  648. X.SH SEE ALSO
  649. Xfbm(1) for general discussion, pbm(1) for PBM routines.
  650. X.SH BUGS
  651. XNone known.
  652. X.SH HISTORY
  653. XCopyright (c) 1989 by Michael L. Mauldin.  
  654. XPermission is granted to use this program in whole or in part provided
  655. Xthat you do not sell it for profit and that this copyright notice is
  656. Xretained unchanged.
  657. X.TP
  658. X07-Mar-89  Michael L. Mauldin at Carnegie Mellon University
  659. XBeta release (version 0.9) mlm@cs.cmu.edu
  660. END_OF_FILE
  661. if test 2772 -ne `wc -c <'fbext.1'`; then
  662.     echo shar: \"'fbext.1'\" unpacked with wrong size!
  663. fi
  664. # end of 'fbext.1'
  665. fi
  666. if test -f 'fbhist.c' -a "${1}" != "-c" ; then 
  667.   echo shar: Will not clobber existing file \"'fbhist.c'\"
  668. else
  669. echo shar: Extracting \"'fbhist.c'\" \(2725 characters\)
  670. sed "s/^X//" >'fbhist.c' <<'END_OF_FILE'
  671. X/*****************************************************************
  672. X * fbhist.c: FBM Library 0.9 (Beta test) 07-Mar-89  Michael Mauldin
  673. X *
  674. X * Copyright (C) 1989 by Michael Mauldin.  Permission is granted to
  675. X * use this file in whole or in part provided that you do not sell it
  676. X * for profit and that this copyright notice is retained unchanged.
  677. X *
  678. X * fbhist.c: 
  679. X *
  680. X * USAGE
  681. X *    % fbhist [-h] < image
  682. X *
  683. X * EDITLOG
  684. X *    LastEditDate = Tue Mar  7 17:52:50 1989 - Michael Mauldin
  685. X *    LastFileName = /usr2/mlm/src/misc/fbm/fbhist.c
  686. X *
  687. X * HISTORY
  688. X * 07-Mar-89  Michael Mauldin (mlm) at Carnegie Mellon University
  689. X *    Beta release (version 0.9) mlm@cs.cmu.edu
  690. X *
  691. X * 21-Aug-88  Michael Mauldin (mlm) at Carnegie-Mellon University
  692. X *    Created.
  693. X *****************************************************************/
  694. X
  695. X# include <stdio.h>
  696. X# include <math.h>
  697. X# include "fbm.h"
  698. X
  699. X#define USAGE "Usage: fbhist [ -h ] < 8bit"
  700. X
  701. X#ifndef lint
  702. Xstatic char *fbmid =
  703. X    "$FBM fbhist.c <0.9> 07-Mar-89  (C) 1989 by Michael Mauldin$";
  704. X#endif
  705. X
  706. Xmain (argc, argv)
  707. Xchar *argv[];
  708. X{ FBM image;
  709. X  register int ch, size, cnt;
  710. X  register unsigned char *bmptr, *tail;
  711. X  int min = BYTE, max = -1;
  712. X  int hist[BYTE], dohist = 0;
  713. X  double sum = 0.0, sumsq = 0.0, avg, std;
  714. X
  715. X  /* Get the options */
  716. X  while (--argc > 0 && (*++argv)[0] == '-')
  717. X  { while (*++(*argv))
  718. X    { switch (**argv)
  719. X      { case 'h':    dohist++; break;
  720. X    default:        fprintf (stderr, "%s\n", USAGE);
  721. X                        exit (1);
  722. X      }
  723. X    }
  724. X  }
  725. X
  726. X  /* Clear the memory pointer so alloc_fbm won't be confused */
  727. X  image.cm  = image.bm  = (unsigned char *) NULL;
  728. X
  729. X  /* Clear the histogram */
  730. X  for (ch=0; ch<BYTE; ch++)
  731. X  { hist[ch] = 0; }
  732. X
  733. X  /* Read the file and count the gray levels */
  734. X  if (read_bitmap (&image, (char *) NULL))
  735. X  { size = image.hdr.rows * image.hdr.cols;
  736. X    bmptr = image.bm;
  737. X    tail = bmptr+size;
  738. X
  739. X    while (bmptr < tail)
  740. X    { hist[*bmptr++]++; }
  741. X    
  742. X    for (ch=0; ch<BYTE; ch++)
  743. X    { cnt = hist[ch];
  744. X
  745. X      if (cnt && ch < min) min = ch;
  746. X      if (cnt && ch > max) max = ch;
  747. X      
  748. X      sum += cnt * ch;
  749. X      sumsq += cnt * ch*ch;
  750. X    }
  751. X    
  752. X    avg = sum / size;
  753. X
  754. X    if (size < 2)
  755. X    { std = 0.0; }
  756. X    else
  757. X    { double t1 = (size * sumsq - sum * sum);
  758. X      double t2 = ((double) size * (size-1));
  759. X      std = sqrt (t1 / t2);
  760. X    }
  761. X
  762. X    printf ("%s [%dx%d  %d bits  %1.3lf aspect ratio]\n",
  763. X        *image.hdr.title ? image.hdr.title : "Untitled",
  764. X        image.hdr.cols, image.hdr.rows, image.hdr.bits, image.hdr.aspect);
  765. X
  766. X    printf ("Mean %1.2lf +- %1.2lf, range %d..%d\n",
  767. X        avg, std, min, max);
  768. X
  769. X    if (dohist)
  770. X    { for (ch=0; ch<BYTE; ch++)
  771. X      { if (hist[ch]) printf ("%3d: %6d\n", ch, hist[ch]); }
  772. X    }
  773. X    
  774. X  }
  775. X  else
  776. X  { exit (1); }
  777. X  
  778. X  exit (0);
  779. X}
  780. END_OF_FILE
  781. if test 2725 -ne `wc -c <'fbhist.c'`; then
  782.     echo shar: \"'fbhist.c'\" unpacked with wrong size!
  783. fi
  784. # end of 'fbhist.c'
  785. fi
  786. if test -f 'fbinfo.c' -a "${1}" != "-c" ; then 
  787.   echo shar: Will not clobber existing file \"'fbinfo.c'\"
  788. else
  789. echo shar: Extracting \"'fbinfo.c'\" \(2683 characters\)
  790. sed "s/^X//" >'fbinfo.c' <<'END_OF_FILE'
  791. X/*****************************************************************
  792. X * fbinfo.c: FBM Library 0.93 (Beta test) 03-May-89  Michael Mauldin
  793. X *
  794. X * Copyright (C) 1989 by Michael Mauldin.  Permission is granted to
  795. X * use this file in whole or in part provided that you do not sell it
  796. X * for profit and that this copyright notice is retained unchanged.
  797. X *
  798. X * fbinfo.c: 
  799. X *
  800. X * USAGE
  801. X *    % fbinfo files...
  802. X *
  803. X * EDITLOG
  804. X *    LastEditDate = Wed May  3 23:07:18 1989 - Michael Mauldin
  805. X *    LastFileName = /usr2/mlm/src/misc/fbm/fbinfo.c
  806. X *
  807. X * HISTORY
  808. X * 03-May-89  Michael Mauldin (mlm) at Carnegie Mellon University
  809. X *    Beta release (version 0.93) mlm@cs.cmu.edu
  810. X *
  811. X * 26-Sep-88  Michael Mauldin (mlm) at Carnegie-Mellon University
  812. X *    Created.
  813. X *****************************************************************/
  814. X
  815. X
  816. X# include <stdio.h>
  817. X# include <math.h>
  818. X# include "fbm.h"
  819. X
  820. X# define USAGE "Usage: fbinfo files..."
  821. X
  822. X#ifndef lint
  823. Xstatic char *fbmid =
  824. X    "$FBM fbinfo.c <0.93> 03-May-89  (C) 1989 by Michael Mauldin$";
  825. X#endif
  826. X
  827. Xmain (argc, argv)
  828. Xchar *argv[];
  829. X{ register int i;
  830. X  FILE *infile;
  831. X  char name[128], cmd[256];
  832. X
  833. X  if (argc == 1)
  834. X  { binfo ((char *) NULL, stdin); }
  835. X  else
  836. X  { for (i=1; i<argc; i++)
  837. X    { strcpy (name, argv[i]);
  838. X
  839. X      if (strcmp (name + strlen (name) - 2, ".Z") == 0)
  840. X      { sprintf (cmd, "(uncompress < %s | select 0 255) 2> /dev/null", name); 
  841. X        if (infile = popen (cmd, "r"))
  842. X    { binfo (name, infile); pclose (infile); }
  843. X    else
  844. X    { perror (cmd); }
  845. X      }
  846. X      else if (infile = fopen (argv[i], "r"))
  847. X      { binfo (argv[i], infile); fclose (infile); }
  848. X      else
  849. X      { perror (argv[i]); }
  850. X    }
  851. X  }
  852. X}
  853. X
  854. Xbinfo (name, file)
  855. Xchar *name;
  856. XFILE *file;
  857. X{ FBM image;
  858. X  FBMHDR *hdr;
  859. X
  860. X  image.cm = image.bm = (unsigned char *) NULL;
  861. X
  862. X  /* Read the file header format the bitmap description */
  863. X  if (read_hdr_fbm (&image, file, (char *) NULL, 0))
  864. X  { hdr = &(image.hdr);
  865. X
  866. X    if (name) printf ("%-15s\t", name);
  867. X
  868. X    if (hdr->title[0])        { printf ("\"%s\"\n", hdr->title); }
  869. X    else            { printf ("(untitled)\n"); }
  870. X
  871. X    if (hdr->credits[0])
  872. X    { if (name) printf ("\t\t");
  873. X      printf ("[ %s ]\n", hdr->credits);
  874. X    }
  875. X    
  876. X    if (name) printf ("\t\t");
  877. X
  878. X    if (hdr->planes == 1)
  879. X    { printf ("[%dx%dx%d]    %d physbits  %1.4lg aspect ratio\n",
  880. X          hdr->cols, hdr->rows, hdr->bits, hdr->physbits, hdr->aspect);
  881. X    }
  882. X    else
  883. X    { printf ("[%dx%dx%dx%d]  %d physbits  %1.4lg aspect ratio\n",
  884. X          hdr->planes, hdr->cols, hdr->rows, hdr->bits, hdr->physbits, 
  885. X          hdr->aspect);
  886. X    }
  887. X
  888. X    if (name) printf ("\t\t");
  889. X
  890. X    printf ("row length %d, plane length %d, colormap length %d\n",
  891. X        hdr->rowlen, hdr->plnlen, hdr->clrlen);
  892. X
  893. X    return (1);
  894. X  }
  895. X
  896. X  return (0);
  897. X}
  898. END_OF_FILE
  899. if test 2683 -ne `wc -c <'fbinfo.c'`; then
  900.     echo shar: \"'fbinfo.c'\" unpacked with wrong size!
  901. fi
  902. # end of 'fbinfo.c'
  903. fi
  904. if test -f 'fbmask.c' -a "${1}" != "-c" ; then 
  905.   echo shar: Will not clobber existing file \"'fbmask.c'\"
  906. else
  907. echo shar: Extracting \"'fbmask.c'\" \(2815 characters\)
  908. sed "s/^X//" >'fbmask.c' <<'END_OF_FILE'
  909. X/*****************************************************************
  910. X * fbmask.c: FBM Library 0.9 (Beta test) 07-Mar-89  Michael Mauldin
  911. X *
  912. X * Copyright (C) 1989 by Michael Mauldin.  Permission is granted to
  913. X * use this file in whole or in part provided that you do not sell it
  914. X * for profit and that this copyright notice is retained unchanged.
  915. X *
  916. X * fbmask.c: Mask a rectangle with a value (or average)
  917. X *
  918. X * USAGE
  919. X *    % fbmask [ flags ] arguments
  920. X *
  921. X * EDITLOG
  922. X *    LastEditDate = Tue Mar  7 19:56:33 1989 - Michael Mauldin
  923. X *    LastFileName = /usr2/mlm/src/misc/fbm/fbmask.c
  924. X *
  925. X * HISTORY
  926. X * 07-Mar-89  Michael Mauldin (mlm) at Carnegie Mellon University
  927. X *    Beta release (version 0.9) mlm@cs.cmu.edu
  928. X *
  929. X * 29-Aug-88  Michael Mauldin (mlm) at Carnegie-Mellon University
  930. X *    Created.
  931. X *****************************************************************/
  932. X
  933. X# include <stdio.h>
  934. X# include <math.h>
  935. X# include "fbm.h"
  936. X
  937. X# define USAGE "Usage: fbmask [ -<type> ] x0 y0 x1 y1 value < 8bit > 8bit"
  938. X
  939. X#ifndef lint
  940. Xstatic char *fbmid =
  941. X    "$FBM fbmask.c <0.9> 07-Mar-89  (C) 1989 by Michael Mauldin$";
  942. X#endif
  943. X
  944. Xmain (argc, argv)
  945. Xchar *argv[];
  946. X{ FBM image;
  947. X  register int j, i, val, rowlen;
  948. X  int x1, x0, y1, y0, n;
  949. X  int outtype = DEF_8BIT;
  950. X
  951. X  /* Clear the memory pointer so alloc_fbm won't be confused */
  952. X  image.cm  = image.bm  = (unsigned char *) NULL;
  953. X
  954. X  /* Get the options */
  955. X  while (--argc > 0 && (*++argv)[0] == '-')
  956. X  { while (*++(*argv))
  957. X    { switch (**argv)
  958. X      {
  959. X    case 'A':    outtype = FMT_ATK; break;
  960. X    case 'B':    outtype = FMT_FACE; break;
  961. X    case 'F':    outtype = FMT_FBM; break;
  962. X    case 'G':    outtype = FMT_GIF; break;
  963. X    case 'I':    outtype = FMT_IFF; break;
  964. X    case 'L':    outtype = FMT_LEAF; break;
  965. X    case 'M':    outtype = FMT_MCP; break;
  966. X    case 'P':    outtype = FMT_PBM; break;
  967. X    case 'S':    outtype = FMT_SUN; break;
  968. X    case 'T':    outtype = FMT_TIFF; break;
  969. X    case 'X':    outtype = FMT_X11; break;
  970. X    case 'Z':    outtype = FMT_PCX; break;
  971. X    default:        fprintf (stderr, "%s\n", USAGE);
  972. X                        exit (1);
  973. X      }
  974. X    }
  975. X  }
  976. X
  977. X  /* Get arguments */
  978. X  if (argc != 5)
  979. X  { fprintf (stderr, "%s\n", USAGE);
  980. X    exit (1);
  981. X  }
  982. X
  983. X  x0  = atoi (argv[0]);
  984. X  y0  = atoi (argv[1]);
  985. X  x1  = atoi (argv[2]);
  986. X  y1  = atoi (argv[3]);
  987. X  val = atoi (argv[4]);
  988. X  
  989. X  /* Assure x0<x1 and y0<y1, swap if necessary */
  990. X  if (x0 > x1) { n=x0; x0=x1; x1=n; }
  991. X  if (y0 > y1) { n=y0; y0=y1; y1=n; }
  992. X
  993. X  if (read_bitmap (&image, (char *) NULL))
  994. X  {
  995. X    if (image.hdr.planes > 1 ||
  996. X        image.hdr.clrlen > 0 ||
  997. X        image.hdr.physbits != 8)
  998. X    { fprintf (stderr, "fbmask works only for 8bit grayscale files\n");
  999. X      exit (1);
  1000. X    }
  1001. X
  1002. X    rowlen = image.hdr.rowlen;
  1003. X
  1004. X    for (j=y0; j<=y1; j++)
  1005. X    { for (i=x0; i<=x1; i++)
  1006. X      { image.bm[j*rowlen + i] = val; }
  1007. X    }
  1008. X    
  1009. X    write_bitmap (&image, stdout, outtype);
  1010. X  }
  1011. X  else
  1012. X  { exit (1); }
  1013. X  
  1014. X  exit (0);
  1015. X}
  1016. END_OF_FILE
  1017. if test 2815 -ne `wc -c <'fbmask.c'`; then
  1018.     echo shar: \"'fbmask.c'\" unpacked with wrong size!
  1019. fi
  1020. # end of 'fbmask.c'
  1021. fi
  1022. if test -f 'fbquant.1' -a "${1}" != "-c" ; then 
  1023.   echo shar: Will not clobber existing file \"'fbquant.1'\"
  1024. else
  1025. echo shar: Extracting \"'fbquant.1'\" \(2737 characters\)
  1026. sed "s/^X//" >'fbquant.1' <<'END_OF_FILE'
  1027. X.TH FBQUANT 1 07-Apr-89
  1028. X.CM 3
  1029. X.SH NAME
  1030. Xfbquant \- quantize a 24 bit color image
  1031. X.SH SYNOPSIS
  1032. X.nf
  1033. Xfbquant [ -c<numcolors> ] [ -<type> ] [ -m<map> ] < rgb-image > mapped-image
  1034. X.fi
  1035. X.SH DESCRIPTION
  1036. X.PP
  1037. XConverts a 3 plane red-green-blue color image into a
  1038. Xmapped color image.  Uses Heckbert's adaptive partitioning
  1039. Xcolor quantizing algorithm.  It is strongly suggested that you make the
  1040. Xnumber of colors used a power of 2, but not necessary for proper
  1041. Xoperation of FBM.
  1042. X.sp
  1043. XIf you wish to requantize an image that is already mapped (for example,
  1044. Xto reduce the number of colors), use "gray2clr -u" to unmap the image
  1045. Xfirst.  This unmapping step is also necessary to resize a color image
  1046. Xusing fbext(1).
  1047. X.sp
  1048. XYou may specify a particular color map with the
  1049. X.B -m
  1050. Xoption.  The argument is another mapped color image.
  1051. X.sp
  1052. XNote that even if you specify fewer than 256 colors, some output
  1053. Xformats (SUN and FBM) will still use 8 bits to store each color index.
  1054. XThe color map will be the specified length.
  1055. X.SH OPTIONS
  1056. X.TP
  1057. X.BR -c<num>
  1058. X.I number of colors
  1059. Xto use for dithering.  The range is 8 to 256, and the default is 256.
  1060. X.TP
  1061. X.BR -m<map>
  1062. X.I colormap
  1063. Xoption, specifies that the colormap from the
  1064. X.I map
  1065. Ximage is to be used to quantize he input.  Colormaps may be efficiently
  1066. Xstored by extracting very small rectangles
  1067. Xfrom another color image:
  1068. X.sp
  1069. X    % fbext 0 0 1 1 < image.clr > map.clr
  1070. X.sp
  1071. Xwhich stores a 1 pixel image with the desired map.
  1072. X.TP
  1073. X.BR -F
  1074. X.I FBM,
  1075. Xformat (by default, the default).  You are guaranteed not
  1076. Xto lose information by specifying FBM as the default.
  1077. X.TP
  1078. X.BR -G
  1079. X.I GIF,
  1080. XCompuserve GIF format.
  1081. X.TP
  1082. X.BR -I
  1083. X.I IFF
  1084. Xformat, interleaved bitmaps (ILBM), used by Amigas.
  1085. XIt is recommended that you use 16 or 32 colors, because the EL Arts
  1086. Xcode limits IFF files to 6 planes, and most Amiga software cannot
  1087. Xhandle more than 32 colors anyway.
  1088. X.TP
  1089. X.BR -S
  1090. X.I sun,
  1091. XSun rasterfiles (not run length encoded).
  1092. X.SH EXAMPLE
  1093. X.PP
  1094. XTo convert a 24 bit Sun rasterfile to an 8 bit mapped color rasterfile:
  1095. X.sp
  1096. X    % fbquant -S < foo.24bit > foo.clr
  1097. X.sp
  1098. XTo convert a 24 bit Sun rasterfile to a 32 color Amiga image:
  1099. X.sp
  1100. X    % fbext -a1.2 -w320 < foo.24bit | \
  1101. X.br
  1102. X      fbquant -I -c32 > foo.iff
  1103. X.sp
  1104. XTo convert an FBM format RGB color image to a 16 color GIF image:
  1105. X    % fbext -a1.2 -w320 < foo.24bit | \
  1106. X.br
  1107. X      fbquant -G -c16 > foo.gif
  1108. X.SH SEE ALSO
  1109. Xfbm(1) for general discussion, pbm(1) for PBM routines.
  1110. X.SH BUGS
  1111. XNone known.
  1112. X.SH HISTORY
  1113. XCopyright (c) 1989 by Michael L. Mauldin.  
  1114. XPermission is granted to use this program in whole or in part provided
  1115. Xthat you do not sell it for profit and that this copyright notice is
  1116. Xretained unchanged.
  1117. X.TP
  1118. X07-Mar-89  Michael L. Mauldin at Carnegie Mellon University
  1119. XBeta release (version 0.9) mlm@cs.cmu.edu
  1120. END_OF_FILE
  1121. if test 2737 -ne `wc -c <'fbquant.1'`; then
  1122.     echo shar: \"'fbquant.1'\" unpacked with wrong size!
  1123. fi
  1124. # end of 'fbquant.1'
  1125. fi
  1126. if test -f 'fbrot.c' -a "${1}" != "-c" ; then 
  1127.   echo shar: Will not clobber existing file \"'fbrot.c'\"
  1128. else
  1129. echo shar: Extracting \"'fbrot.c'\" \(2490 characters\)
  1130. sed "s/^X//" >'fbrot.c' <<'END_OF_FILE'
  1131. X/*****************************************************************
  1132. X * fbrot.c: FBM Library 0.9 (Beta test) 07-Mar-89  Michael Mauldin
  1133. X *
  1134. X * Copyright (C) 1989 by Michael Mauldin.  Permission is granted to
  1135. X * use this file in whole or in part provided that you do not sell it
  1136. X * for profit and that this copyright notice is retained unchanged.
  1137. X *
  1138. X * fbrot.c: Rotate image 90 degrees clockwise
  1139. X *
  1140. X * USAGE
  1141. X *     % fbrot < image1 > image2
  1142. X *
  1143. X * EDITLOG
  1144. X *     LastEditDate = Tue Mar  7 19:56:41 1989 - Michael Mauldin
  1145. X *     LastFileName = /usr2/mlm/src/misc/fbm/fbrot.c
  1146. X *
  1147. X * HISTORY
  1148. X * 07-Mar-89  Michael Mauldin (mlm) at Carnegie Mellon University
  1149. X *    Beta release (version 0.9) mlm@cs.cmu.edu
  1150. X *
  1151. X * 22-Aug-88  Michael Mauldin (mlm) at Carnegie-Mellon University
  1152. X *     Created.
  1153. X *****************************************************************/
  1154. X
  1155. X# include <stdio.h>
  1156. X# include <math.h>
  1157. X# include "fbm.h"
  1158. X
  1159. X# define USAGE \
  1160. X  "Usage: fbrot [ -<type> ] [ -90 | -180 | -270 ] < image > image"
  1161. X
  1162. X#ifndef lint
  1163. Xstatic char *fbmid =
  1164. X    "$FBM fbrot.c <0.9> 07-Mar-89  (C) 1989 by Michael Mauldin$";
  1165. X#endif
  1166. X
  1167. Xmain (argc, argv)
  1168. Xchar *argv[];
  1169. X{ FBM input, output;
  1170. X  int outtype = -1, rot = 90;
  1171. X
  1172. X  /* Get the options */
  1173. X  while (--argc > 0 && (*++argv)[0] == '-')
  1174. X  { while (*++(*argv))
  1175. X    { switch (**argv)
  1176. X      {
  1177. X    case '9':    rot=90; SKIPARG; break;
  1178. X    case '1':    rot=180; SKIPARG; break;
  1179. X    case '2':    rot=270; SKIPARG; break;
  1180. X    case 'A':    outtype = FMT_ATK; break;
  1181. X    case 'B':    outtype = FMT_FACE; break;
  1182. X    case 'F':    outtype = FMT_FBM; break;
  1183. X    case 'G':    outtype = FMT_GIF; break;
  1184. X    case 'I':    outtype = FMT_IFF; break;
  1185. X    case 'L':    outtype = FMT_LEAF; break;
  1186. X    case 'M':    outtype = FMT_MCP; break;
  1187. X    case 'P':    outtype = FMT_PBM; break;
  1188. X    case 'S':    outtype = FMT_SUN; break;
  1189. X    case 'T':    outtype = FMT_TIFF; break;
  1190. X    case 'X':    outtype = FMT_X11; break;
  1191. X    case 'Z':    outtype = FMT_PCX; break;
  1192. X    default:        fprintf (stderr, "%s\n", USAGE);
  1193. X                        exit (1);
  1194. X      }
  1195. X    }
  1196. X  }
  1197. X
  1198. X  /* Clear the memory pointers so alloc_fbm won't be confused */
  1199. X  input.cm  = input.bm  = (unsigned char *) NULL;
  1200. X  output.cm = output.bm = (unsigned char *) NULL;
  1201. X
  1202. X  /* Read the image and rotate it */
  1203. X  if (read_bitmap (&input, (char *) NULL))
  1204. X  { if (outtype < 0)
  1205. X    { if (input.hdr.planes == 1 && input.hdr.bits == 1)
  1206. X      { outtype = DEF_1BIT; }
  1207. X      else
  1208. X      { outtype = DEF_8BIT; }
  1209. X    }
  1210. X
  1211. X    if (rotate_fbm (&input, &output, rot) &&
  1212. X        write_bitmap (&output, stdout, outtype))
  1213. X    { exit (0); }
  1214. X  }
  1215. X
  1216. X  exit (1);
  1217. X}
  1218. END_OF_FILE
  1219. if test 2490 -ne `wc -c <'fbrot.c'`; then
  1220.     echo shar: \"'fbrot.c'\" unpacked with wrong size!
  1221. fi
  1222. # end of 'fbrot.c'
  1223. fi
  1224. if test -f 'fbsample.1' -a "${1}" != "-c" ; then 
  1225.   echo shar: Will not clobber existing file \"'fbsample.1'\"
  1226. else
  1227. echo shar: Extracting \"'fbsample.1'\" \(2585 characters\)
  1228. sed "s/^X//" >'fbsample.1' <<'END_OF_FILE'
  1229. X.TH FBSAMPLE 1 07-Mar-89
  1230. X.CM 3
  1231. X.SH NAME
  1232. Xfbsample \- convert 1bit image to grayscale by sampling
  1233. X.SH SYNOPSIS
  1234. X.nf
  1235. Xfbsample [ -t'title' -c'credits' -g'grain' -n'nbr']
  1236. X         [ -<type> ] < bitmap > image
  1237. X.fi
  1238. X.SH DESCRIPTION
  1239. X.PP
  1240. XSamples a 1 bit deep pbm file using a square neighborhood of the
  1241. Xspecified size, and outputs an 8 bit file.  You will want to run
  1242. X.I fbnorm
  1243. Xon the output to expand the scale to 255, and there will be a small
  1244. Xloss of sharpness, so
  1245. X.I fbsharp
  1246. Xwill also be useful.  Once you have an 8 bit file, you can resize it
  1247. Xarbitrarily, and then convert it back to a 1 bit file, if need be.
  1248. XThe default neighborhood size is 8 by 8, which gives 65 different gray
  1249. Xlevels.
  1250. X.SH OPTIONS
  1251. X.TP
  1252. X.B -g
  1253. X.I grain
  1254. Xsize.  The sample is taken every
  1255. X.I grain
  1256. Xpixels.
  1257. X.TP
  1258. X.B -n
  1259. X.I neighborhood
  1260. Xsize.  The value will be the number of light pixels in the nearby NxN
  1261. Xsquare.  The values can range from 1 to 16.
  1262. X.TP
  1263. X.BR -t'title'
  1264. X.I title,
  1265. Xspecify a character string (up to 80 characters) to describe the image.
  1266. XThe default is no title.
  1267. X.TP
  1268. X.BR -c'credits'
  1269. X.I credits or subtitle,
  1270. Xspecify a second character string (up to 80 characters) to describe the
  1271. Ximage.  The default is no credit string.
  1272. X.TP
  1273. X.BR -B
  1274. X.I face
  1275. Xformat, as used by Bennet Yee's
  1276. X.I face
  1277. Xprogram at CMU. 
  1278. X.TP
  1279. X.BR -F
  1280. X.I FBM,
  1281. Xformat (by default, the default).  You are guaranteed not
  1282. Xto lose information by specifying FBM as the default.
  1283. X.TP
  1284. X.BR -G
  1285. X.I GIF,
  1286. XCompuserve GIF format.
  1287. X.TP
  1288. X.BR -I
  1289. X.I IFF
  1290. Xformat, interleaved bitmaps (ILBM), used by Amigas.
  1291. X.TP
  1292. X.BR -P
  1293. X.I PBM,
  1294. XJef Poskanzer's bitmap format.
  1295. X.TP
  1296. X.BR -S
  1297. X.I sun,
  1298. XSun rasterfiles (not run length encoded).
  1299. X.PP
  1300. X.SH EXAMPLE
  1301. X.PP
  1302. XSuppose you have a 480 by 600 face format file (-B) that you wish to
  1303. Xshrink to 300 by 375 and convert to PostScript (say for inclusion 
  1304. Xin your door label).  Here's a pipeline to do that:
  1305. X.sp
  1306. X.nf
  1307. X    % fbsample -n5 -g1 < my.face | \    # sample 5x5
  1308. X      fbnorm -b4 -w1 |                  # normalize
  1309. X      fbext -w300 | \                   # make 300 pixels wide
  1310. X      fbhalf -s20 | \                   # halftone and really sharpen
  1311. X      pbm2ps -s 1 > sdoor.ps            # convert to postscript
  1312. X.fi
  1313. X.SH SEE ALSO
  1314. Xfbnorm(1) to normalize the output,
  1315. Xfbm(1) for general discussion, pbm(1) for PBM routines.
  1316. X.SH BUGS
  1317. XNone known.
  1318. X.SH HISTORY
  1319. XCopyright (c) 1989 by Michael L. Mauldin.  
  1320. XPermission is granted to use this program in whole or in part provided
  1321. Xthat you do not sell it for profit and that this copyright notice is
  1322. Xretained unchanged.
  1323. X.TP
  1324. X07-Mar-89  Michael L. Mauldin at Carnegie Mellon University
  1325. XBeta release (version 0.9) mlm@cs.cmu.edu
  1326. END_OF_FILE
  1327. if test 2585 -ne `wc -c <'fbsample.1'`; then
  1328.     echo shar: \"'fbsample.1'\" unpacked with wrong size!
  1329. fi
  1330. # end of 'fbsample.1'
  1331. fi
  1332. if test -f 'fbsharp.c' -a "${1}" != "-c" ; then 
  1333.   echo shar: Will not clobber existing file \"'fbsharp.c'\"
  1334. else
  1335. echo shar: Extracting \"'fbsharp.c'\" \(2905 characters\)
  1336. sed "s/^X//" >'fbsharp.c' <<'END_OF_FILE'
  1337. X/*****************************************************************
  1338. X * fbsharp.c: FBM Library 0.9 (Beta test) 07-Mar-89  Michael Mauldin
  1339. X *
  1340. X * Copyright (C) 1989 by Michael Mauldin.  Permission is granted to
  1341. X * use this file in whole or in part provided that you do not sell it
  1342. X * for profit and that this copyright notice is retained unchanged.
  1343. X *
  1344. X * fbsharp.c: Sharpen an image by using a Laplacian edge enhancement
  1345. X *
  1346. X * USAGE
  1347. X *    % fbsharp [ flags ] arguments
  1348. X *
  1349. X * EDITLOG
  1350. X *    LastEditDate = Tue Mar  7 19:56:44 1989 - Michael Mauldin
  1351. X *    LastFileName = /usr2/mlm/src/misc/fbm/fbsharp.c
  1352. X *
  1353. X * HISTORY
  1354. X * 07-Mar-89  Michael Mauldin (mlm) at Carnegie Mellon University
  1355. X *    Beta release (version 0.9) mlm@cs.cmu.edu
  1356. X *
  1357. X * 10-Sep-88  Michael Mauldin (mlm) at Carnegie-Mellon University
  1358. X *    Created.
  1359. X *****************************************************************/
  1360. X
  1361. X# include <stdio.h>
  1362. X# include <math.h>
  1363. X# include "fbm.h"
  1364. X
  1365. X# define USAGE "fbsharp [ -SF ] beta < 8bit > 8bit"
  1366. X
  1367. X#ifndef lint
  1368. Xstatic char *fbmid =
  1369. X    "$FBM fbsharp.c <0.9> 07-Mar-89  (C) 1989 by Michael Mauldin$";
  1370. X#endif
  1371. X
  1372. Xmain (argc, argv)
  1373. Xchar *argv[];
  1374. X{ int w, h, k;
  1375. X  double beta = 2.0;
  1376. X  FBM input, output;
  1377. X  int outtype = DEF_8BIT;
  1378. X
  1379. X  /* Get the options */
  1380. X  while (--argc > 0 && (*++argv)[0] == '-')
  1381. X  { while (*++(*argv))
  1382. X    { switch (**argv)
  1383. X      { 
  1384. X    case 'A':    outtype = FMT_ATK; break;
  1385. X    case 'B':    outtype = FMT_FACE; break;
  1386. X    case 'F':    outtype = FMT_FBM; break;
  1387. X    case 'G':    outtype = FMT_GIF; break;
  1388. X    case 'I':    outtype = FMT_IFF; break;
  1389. X    case 'L':    outtype = FMT_LEAF; break;
  1390. X    case 'M':    outtype = FMT_MCP; break;
  1391. X    case 'P':    outtype = FMT_PBM; break;
  1392. X    case 'S':    outtype = FMT_SUN; break;
  1393. X    case 'T':    outtype = FMT_TIFF; break;
  1394. X    case 'X':    outtype = FMT_X11; break;
  1395. X    case 'Z':    outtype = FMT_PCX; break;
  1396. X    default:        fprintf (stderr, "%s\n", USAGE);
  1397. X                        exit (1);
  1398. X      }
  1399. X    }
  1400. X  }
  1401. X
  1402. X  /* Clear the memory pointers so alloc_fbm won't be confused */
  1403. X  input.cm  = input.bm  = (unsigned char *) NULL;
  1404. X  output.cm = output.bm = (unsigned char *) NULL;
  1405. X
  1406. X  /* Read the image and sharpen it */
  1407. X  if (read_bitmap (&input, (char *) NULL))
  1408. X  {
  1409. X    if (input.hdr.bits != 8 || input.hdr.physbits != 8)
  1410. X    { fprintf (stderr,
  1411. X           "Can't handle images with %d bits and %d physbits per pixel\n",
  1412. X           input.hdr.bits, input.hdr.physbits);
  1413. X      exit (1);
  1414. X    }
  1415. X
  1416. X    /* Argument is amount of sharpening */
  1417. X    if (argc > 0)        { beta = atof (argv[0]); }
  1418. X
  1419. X    /* Determine output height & width (oh*ow <= size) */
  1420. X    h = input.hdr.rows;
  1421. X    w = input.hdr.cols;
  1422. X    k = input.hdr.planes;
  1423. X
  1424. X    fprintf (stderr,
  1425. X         "Sharpen \"%s\", beta %1.3lf [%dx%dx%d]\n",
  1426. X         input.hdr.title[0] ? input.hdr.title : "(untitled)",
  1427. X         beta, w, h, k);
  1428. X
  1429. X    /* Sharpen the image using a digitial Laplacian */
  1430. X    if (sharpen_fbm (&input, &output, beta) &&
  1431. X        write_bitmap (&output, stdout, outtype))
  1432. X    { exit (0); }
  1433. X  }
  1434. X  
  1435. X  exit (1);
  1436. X}
  1437. END_OF_FILE
  1438. if test 2905 -ne `wc -c <'fbsharp.c'`; then
  1439.     echo shar: \"'fbsharp.c'\" unpacked with wrong size!
  1440. fi
  1441. # end of 'fbsharp.c'
  1442. fi
  1443. if test -f 'flcavg.c' -a "${1}" != "-c" ; then 
  1444.   echo shar: Will not clobber existing file \"'flcavg.c'\"
  1445. else
  1446. echo shar: Extracting \"'flcavg.c'\" \(3162 characters\)
  1447. sed "s/^X//" >'flcavg.c' <<'END_OF_FILE'
  1448. X/*****************************************************************
  1449. X * flcavg.c: FBM Library 0.94 (Beta test) 20-May-89  Michael Mauldin
  1450. X *
  1451. X * Copyright (C) 1989 by Michael Mauldin.  Permission is granted to
  1452. X * use this file in whole or in part provided that you do not sell it
  1453. X * for profit and that this copyright notice is retained unchanged.
  1454. X *
  1455. X * flcavg.c: Constrained average halftoning
  1456. X *
  1457. X * CONTENTS
  1458. X *    constravg_fbm (input, output, gamma)
  1459. X *
  1460. X * EDITLOG
  1461. X *    LastEditDate = Sat May 20 19:07:06 1989 - Michael Mauldin
  1462. X *    LastFileName = /usr2/mlm/src/misc/fbm/flcavg.c
  1463. X *
  1464. X * HISTORY
  1465. X * 20-May-89  Michael Mauldin (mlm) at Carnegie Mellon University
  1466. X *    Bug fix from Dave Cohrs <dave@cs.wisc.edu>
  1467. X *
  1468. X * 07-Mar-89  Michael Mauldin (mlm) at Carnegie Mellon University
  1469. X *    Beta release (version 0.9) mlm@cs.cmu.edu
  1470. X *
  1471. X * 12-Nov-88  Michael Mauldin (mlm) at Carnegie-Mellon University
  1472. X *    Created.
  1473. X *****************************************************************/
  1474. X
  1475. X# include <stdio.h>
  1476. X# include <math.h>
  1477. X# include <ctype.h>
  1478. X# include "fbm.h"
  1479. X
  1480. X/****************************************************************
  1481. X * constravg_fbm: Constrained Average halftoning
  1482. X * Reference: Jarvis & Roberts, IEEE Trans. on Commun., v24n8, p 891-898
  1483. X ****************************************************************/
  1484. X
  1485. X# define NBR 9
  1486. X
  1487. X#ifndef lint
  1488. Xstatic char *fbmid =
  1489. X    "$FBM flcavg.c <0.94> 20-May-89  (C) 1989 by Michael Mauldin$";
  1490. X#endif
  1491. X
  1492. Xconstravg_fbm (input, output, gamma)
  1493. XFBM *input, *output;
  1494. Xdouble gamma;
  1495. X{ register unsigned char *bmp, *obm;
  1496. X  register int i, j, rowlen, w, h, sum, thresh, outrow;
  1497. X  int gamma100 = gamma * 100;
  1498. X
  1499. X  if (input->hdr.planes != 1)
  1500. X  { fprintf (stderr, "constravg_fbm: can't halftone color images\n");
  1501. X    return (0);
  1502. X  }
  1503. X
  1504. X  fprintf (stderr, "Constrained average halftoning, gamma %1.2lf\n", gamma);
  1505. X
  1506. X  /* Allocate output */
  1507. X  output->hdr = input->hdr;
  1508. X  output->hdr.bits = 1;
  1509. X  output->hdr.physbits = 8;
  1510. X  outrow = 16 * ((input->hdr.cols + 15) / 16); /* Pad to even byte boundary */
  1511. X  output->hdr.rowlen = outrow;
  1512. X  output->hdr.plnlen = outrow*output->hdr.rows;
  1513. X  alloc_fbm (output);
  1514. X
  1515. X  w = input->hdr.cols;
  1516. X  h = input->hdr.rows;
  1517. X  rowlen = input->hdr.rowlen;
  1518. X
  1519. X  /* Use threshold of 1/2 in the output border */
  1520. X  for (j=0; j<h; j++)
  1521. X  { output->bm[j*outrow]         = input->bm[j*rowlen]         > (WHITE/2);
  1522. X    output->bm[j*outrow + (w-1)] = input->bm[j*rowlen + (w-1)] > (WHITE/2);
  1523. X  }
  1524. X
  1525. X  for (i=0; i<w; i++)
  1526. X  { output->bm[i]                = input->bm[i]                > (WHITE/2);
  1527. X    output->bm[outrow*(h-1) + i] = input->bm[rowlen*(h-1) + i] > (WHITE/2);
  1528. X  }
  1529. X
  1530. X  /*
  1531. X   * Now process the interior bits (use sum instead of average and divide
  1532. X   * by 9 when we are all done -- this allows fixed point arithmetic)
  1533. X   */
  1534. X
  1535. X  for (j=1; j<h-1; j++)
  1536. X  { bmp = &input->bm[j*rowlen];
  1537. X    obm = &output->bm[j*outrow];
  1538. X
  1539. X    for (i=1; i<w-1; i++)
  1540. X    { sum = bmp[(i-w) - 1] + bmp[(i-w)] + bmp[(i-w) + 1] +
  1541. X        bmp[i-1]       + bmp[i]     + bmp[i+1] +
  1542. X        bmp[i+w-1]     + bmp[i+w]   + bmp[i+w+1];
  1543. X      
  1544. X      thresh = gamma100/100 + (sum*WHITE - 2*gamma100*sum/100) / (NBR*WHITE);
  1545. X      obm[i] = (bmp[i] > thresh) ? 1 : 0;
  1546. X    }
  1547. X  }
  1548. X
  1549. X  return (1);
  1550. X}
  1551. END_OF_FILE
  1552. if test 3162 -ne `wc -c <'flcavg.c'`; then
  1553.     echo shar: \"'flcavg.c'\" unpacked with wrong size!
  1554. fi
  1555. # end of 'flcavg.c'
  1556. fi
  1557. if test -f 'flthre.c' -a "${1}" != "-c" ; then 
  1558.   echo shar: Will not clobber existing file \"'flthre.c'\"
  1559. else
  1560. echo shar: Extracting \"'flthre.c'\" \(2328 characters\)
  1561. sed "s/^X//" >'flthre.c' <<'END_OF_FILE'
  1562. X1/*****************************************************************
  1563. X * flthre.c: FBM Library 0.94 (Beta test) 20-May-89  Michael Mauldin
  1564. X *
  1565. X * Copyright (C) 1989 by Michael Mauldin.  Permission is granted to
  1566. X * use this file in whole or in part provided that you do not sell it
  1567. X * for profit and that this copyright notice is retained unchanged.
  1568. X *
  1569. X * flthre.c: 
  1570. X *
  1571. X * CONTENTS:
  1572. X *    thesh_fbm (input, output, thresh)
  1573. X *
  1574. X * EDITLOG
  1575. X *    LastEditDate = Sat May 20 19:06:37 1989 - Michael Mauldin
  1576. X *    LastFileName = /usr2/mlm/src/misc/fbm/flthre.c
  1577. X *
  1578. X * HISTORY
  1579. X * 20-May-89  Michael Mauldin (mlm) at Carnegie Mellon University
  1580. X *    Bug fix from Dave Cohrs <dave@cs.wisc.edu>
  1581. X *
  1582. X * 07-Mar-89  Michael Mauldin (mlm) at Carnegie Mellon University
  1583. X *    Beta release (version 0.9) mlm@cs.cmu.edu
  1584. X *
  1585. X * 10-Dec-88  Michael Mauldin (mlm) at Carnegie-Mellon University
  1586. X *    Created.
  1587. X *****************************************************************/
  1588. X
  1589. X
  1590. X# include <stdio.h>
  1591. X# include <math.h>
  1592. X# include <ctype.h>
  1593. X# include "fbm.h"
  1594. X
  1595. X/*****************************************************************
  1596. X * thesh_fbm: Threshhold halftoning
  1597. X *****************************************************************/
  1598. X
  1599. X# define RAND(RN) (((seed = 1103515245 * seed + 12345) >> 12) % (RN))
  1600. X
  1601. X#ifndef lint
  1602. Xstatic char *fbmid =
  1603. X    "$FBM flthre.c <0.94> 20-May-89  (C) 1989 by Michael Mauldin$";
  1604. X#endif
  1605. X
  1606. Xthesh_fbm (input, output, thresh)
  1607. XFBM *input, *output;
  1608. Xregister int thresh;
  1609. X{ register unsigned char *bmp, *obm;
  1610. X  register int i, j, rowlen, w, h, outrow;
  1611. X
  1612. X  if (input->hdr.planes != 1)
  1613. X  { fprintf (stderr, "thesh_fbm: can't halftone color images\n");
  1614. X    return (0);
  1615. X  }
  1616. X
  1617. X  fprintf (stderr, "Threshhold halftoning, thesh %d\n", thresh);
  1618. X
  1619. X  /* Allocate output */
  1620. X  free_fbm (output);
  1621. X  output->hdr = input->hdr;
  1622. X  output->hdr.bits = 1;
  1623. X  output->hdr.physbits = 8;
  1624. X  outrow = 16 * ((input->hdr.cols + 15) / 16); /* Pad to even byte boundary */
  1625. X  output->hdr.rowlen = outrow;
  1626. X  output->hdr.plnlen = outrow*output->hdr.rows;
  1627. X  alloc_fbm (output);
  1628. X
  1629. X  w = input->hdr.cols;
  1630. X  h = input->hdr.rows;
  1631. X  rowlen = input->hdr.rowlen;
  1632. X  
  1633. X  /* Now do threshholding */
  1634. X  for (j=0; j<h; j++)
  1635. X  { /* scan left to right */
  1636. X    bmp = &input->bm[j*rowlen];
  1637. X    obm = &output->bm[j*outrow];
  1638. X
  1639. X    for (i=1; i<w; i++)
  1640. X    { obm[i] = bmp[i] > thresh ? WHITE : BLACK; }
  1641. X  }
  1642. X  
  1643. X  return (1);
  1644. X}
  1645. END_OF_FILE
  1646. if test 2328 -ne `wc -c <'flthre.c'`; then
  1647.     echo shar: \"'flthre.c'\" unpacked with wrong size!
  1648. fi
  1649. # end of 'flthre.c'
  1650. fi
  1651. if test -f 'flwrfb.c' -a "${1}" != "-c" ; then 
  1652.   echo shar: Will not clobber existing file \"'flwrfb.c'\"
  1653. else
  1654. echo shar: Extracting \"'flwrfb.c'\" \(2921 characters\)
  1655. sed "s/^X//" >'flwrfb.c' <<'END_OF_FILE'
  1656. X/*****************************************************************
  1657. X * flwrfb.c: FBM Library 0.9 (Beta test) 07-Mar-89  Michael Mauldin
  1658. X *
  1659. X * Copyright (C) 1989 by Michael Mauldin.  Permission is granted to
  1660. X * use this file in whole or in part provided that you do not sell it
  1661. X * for profit and that this copyright notice is retained unchanged.
  1662. X *
  1663. X * flwrfb.c: 
  1664. X *
  1665. X * CONTENTS
  1666. X *    write_fbm (image, wfile)
  1667. X *    write_hdr_fbm (image, wfile)
  1668. X *
  1669. X * EDITLOG
  1670. X *    LastEditDate = Tue Mar  7 19:57:39 1989 - Michael Mauldin
  1671. X *    LastFileName = /usr2/mlm/src/misc/fbm/flwrfb.c
  1672. X *
  1673. X * HISTORY
  1674. X * 07-Mar-89  Michael Mauldin (mlm) at Carnegie Mellon University
  1675. X *    Beta release (version 0.9) mlm@cs.cmu.edu
  1676. X *
  1677. X * 12-Nov-88  Michael Mauldin (mlm) at Carnegie-Mellon University
  1678. X *    Created.
  1679. X *****************************************************************/
  1680. X
  1681. X# include <stdio.h>
  1682. X# include <math.h>
  1683. X# include <ctype.h>
  1684. X# include "fbm.h"
  1685. X
  1686. X/****************************************************************
  1687. X * write_fbm: Write an image to a stream
  1688. X ****************************************************************/
  1689. X
  1690. X#ifndef lint
  1691. Xstatic char *fbmid =
  1692. X    "$FBM flwrfb.c <0.9> 07-Mar-89  (C) 1989 by Michael Mauldin$";
  1693. X#endif
  1694. X
  1695. Xwrite_fbm (image, wfile)
  1696. Xregister FBM *image;
  1697. Xregister FILE *wfile;
  1698. X{ register int k, j, rowlen, plnlen;
  1699. X  register unsigned char *bmptr;
  1700. X
  1701. X  if (! write_hdr_fbm (image, wfile)) return (0);
  1702. X
  1703. X  rowlen = image->hdr.rowlen;
  1704. X  plnlen = image->hdr.plnlen;
  1705. X  
  1706. X  if (image->hdr.clrlen > 0)
  1707. X  { if (!fwrite (image->cm, image->hdr.clrlen, 1, wfile))
  1708. X    { perror ("write_fbm (colormap)"); return (0); }
  1709. X  }
  1710. X
  1711. X  for (k=0; k<image->hdr.planes; k++)
  1712. X  { bmptr = &(image->bm[k*plnlen]);
  1713. X    
  1714. X    for (j=0; j<image->hdr.rows; j++, bmptr += rowlen)
  1715. X    { if (! fwrite (bmptr, 1, rowlen, wfile))
  1716. X      { perror ("write_fbm"); return (0); }
  1717. X    }
  1718. X  }
  1719. X    
  1720. X  return (1);
  1721. X}
  1722. X
  1723. X/****************************************************************
  1724. X * write_hdr_fbm: Write an image header to a stream
  1725. X ****************************************************************/
  1726. X
  1727. Xwrite_hdr_fbm (image, wfile)
  1728. Xregister FBM *image;
  1729. Xregister FILE *wfile;
  1730. X{ FBMFILEHDR file_hdr;
  1731. X
  1732. X  strncpy (file_hdr.magic, FBM_MAGIC, 8);
  1733. X  sprintf (file_hdr.cols, "%7d", image->hdr.cols);
  1734. X  sprintf (file_hdr.rows, "%7d", image->hdr.rows);
  1735. X  sprintf (file_hdr.planes, "%7d", image->hdr.planes);
  1736. X  sprintf (file_hdr.bits, "%7d", image->hdr.bits);
  1737. X  sprintf (file_hdr.physbits, "%7d", image->hdr.physbits);
  1738. X  sprintf (file_hdr.rowlen, "%11d", image->hdr.rowlen);
  1739. X  sprintf (file_hdr.plnlen, "%11d", image->hdr.plnlen);
  1740. X  sprintf (file_hdr.clrlen, "%11d", image->hdr.clrlen);
  1741. X  sprintf (file_hdr.aspect, "%11.6lf", image->hdr.aspect);
  1742. X  strncpy (file_hdr.title, image->hdr.title, FBM_MAX_TITLE);
  1743. X  strncpy (file_hdr.credits, image->hdr.credits, FBM_MAX_TITLE);
  1744. X
  1745. X  if (! fwrite (&file_hdr, sizeof (file_hdr), 1, wfile))
  1746. X  { perror ("write_fbm (header)"); return (0); }
  1747. X    
  1748. X  return (1);
  1749. X}
  1750. END_OF_FILE
  1751. if test 2921 -ne `wc -c <'flwrfb.c'`; then
  1752.     echo shar: \"'flwrfb.c'\" unpacked with wrong size!
  1753. fi
  1754. # end of 'flwrfb.c'
  1755. fi
  1756. if test -f 'gray2clr.c' -a "${1}" != "-c" ; then 
  1757.   echo shar: Will not clobber existing file \"'gray2clr.c'\"
  1758. else
  1759. echo shar: Extracting \"'gray2clr.c'\" \(2410 characters\)
  1760. sed "s/^X//" >'gray2clr.c' <<'END_OF_FILE'
  1761. X/*****************************************************************
  1762. X * gray2clr.c: FBM Library 0.9 (Beta test) 07-Mar-89  Michael Mauldin
  1763. X *
  1764. X * Copyright (C) 1989 by Michael Mauldin.  Permission is granted to
  1765. X * use this file in whole or in part provided that you do not sell it
  1766. X * for profit and that this copyright notice is retained unchanged.
  1767. X *
  1768. X * gray2clr.c: 
  1769. X *
  1770. X * USAGE
  1771. X *    % gray2clr [ flags ] arguments
  1772. X *
  1773. X * EDITLOG
  1774. X *    LastEditDate = Thu Apr 20 17:05:31 1989 - Michael Mauldin
  1775. X *    LastFileName = /usr2/mlm/src/misc/fbm/gray2clr.c
  1776. X *
  1777. X * HISTORY
  1778. X * 07-Mar-89  Michael Mauldin (mlm) at Carnegie Mellon University
  1779. X *    Beta release (version 0.9) mlm@cs.cmu.edu
  1780. X *
  1781. X *  1-Dec-88  Michael Mauldin (mlm) at Carnegie-Mellon University
  1782. X *    Created.
  1783. X *****************************************************************/
  1784. X
  1785. X# include <stdio.h>
  1786. X# include <math.h>
  1787. X# include "fbm.h"
  1788. X
  1789. X# define USAGE "gray2clr [ -<type> ] [ -u ] < gray > color"
  1790. X
  1791. X#ifndef lint
  1792. Xstatic char *fbmid =
  1793. X    "$FBM gray2clr.c <0.9> 07-Mar-89  (C) 1989 by Michael Mauldin$";
  1794. X#endif
  1795. X
  1796. Xmain (argc, argv)
  1797. Xchar *argv[];
  1798. X{ FBM input, output;
  1799. X  int outtype = DEF_8BIT;
  1800. X  int mapped = 1;
  1801. X
  1802. X  /* If invoked as 'unmap', set option to mapped=0 */
  1803. X  if (strcmp (argv[0] + strlen (argv[0]) - 5, "unmap") == 0)
  1804. X  { mapped = 0; }
  1805. X
  1806. X  /* Get the options */
  1807. X  while (--argc > 0 && (*++argv)[0] == '-')
  1808. X  { while (*++(*argv))
  1809. X    { switch (**argv)
  1810. X      { case 'u':    mapped = 0; break;
  1811. X    case 'A':    outtype = FMT_ATK; break;
  1812. X    case 'B':    outtype = FMT_FACE; break;
  1813. X    case 'F':    outtype = FMT_FBM; break;
  1814. X    case 'G':    outtype = FMT_GIF; break;
  1815. X    case 'I':    outtype = FMT_IFF; break;
  1816. X    case 'L':    outtype = FMT_LEAF; break;
  1817. X    case 'M':    outtype = FMT_MCP; break;
  1818. X    case 'P':    outtype = FMT_PBM; break;
  1819. X    case 'S':    outtype = FMT_SUN; break;
  1820. X    case 'T':    outtype = FMT_TIFF; break;
  1821. X    case 'X':    outtype = FMT_X11; break;
  1822. X    case 'Z':    outtype = FMT_PCX; break;
  1823. X    default:        fprintf (stderr, "%s\n", USAGE);
  1824. X                        exit (1);
  1825. X      }
  1826. X    }
  1827. X  }
  1828. X
  1829. X  /* Clear the memory pointers so alloc_fbm won't be confused */
  1830. X  input.cm  = input.bm  = (unsigned char *) NULL;
  1831. X  output.cm = output.bm = (unsigned char *) NULL;
  1832. X
  1833. X  /* Read the image and convert it */
  1834. X  if (read_bitmap (&input, (char *) NULL) &&
  1835. X      (mapped ?
  1836. X       gray2clr (&input, &output, outtype == FMT_SUN) :
  1837. X       clr_unmap (&input, &output)) &&
  1838. X      write_bitmap (&output, stdout, outtype))
  1839. X  { exit (0); }
  1840. X
  1841. X  exit (1);
  1842. X}
  1843. END_OF_FILE
  1844. if test 2410 -ne `wc -c <'gray2clr.c'`; then
  1845.     echo shar: \"'gray2clr.c'\" unpacked with wrong size!
  1846. fi
  1847. # end of 'gray2clr.c'
  1848. fi
  1849. if test -f 'qrt2fbm.c' -a "${1}" != "-c" ; then 
  1850.   echo shar: Will not clobber existing file \"'qrt2fbm.c'\"
  1851. else
  1852. echo shar: Extracting \"'qrt2fbm.c'\" \(2571 characters\)
  1853. sed "s/^X//" >'qrt2fbm.c' <<'END_OF_FILE'
  1854. X/*****************************************************************
  1855. X * qrt2fbm.c: FBM Library 0.91 (Beta Test)  7-Apr-89  Michael Mauldin
  1856. X *
  1857. X * Copyright (C) 1989 by Michael Mauldin.  Permission is granted to
  1858. X * use this file in whole or in part provided that you do not sell it
  1859. X * for profit and that this copyright notice is retained unchanged.
  1860. X *
  1861. X * qrt2fbm.c: Convert QRT format (from the QRT ray tracer)
  1862. X *
  1863. X * USAGE
  1864. X *     % qrt2fbm -t'title' -c'credits' < qrtfile > fbm
  1865. X *
  1866. X * EDITLOG
  1867. X *    LastEditDate = Wed May  3 23:35:24 1989 - Michael Mauldin
  1868. X *    LastFileName = /usr2/mlm/src/misc/fbm/qrt2fbm.c
  1869. X *
  1870. X * HISTORY
  1871. X *  7-Apr-89  Michael Mauldin (mlm) at Carnegie-Mellon University
  1872. X *    Installed, code by Butler Hines.
  1873. X *
  1874. X *****************************************************************/
  1875. X
  1876. X# include <stdio.h>
  1877. X# include "fbm.h"
  1878. X
  1879. X# define USAGE \
  1880. X"Usage: qrt2fbm [ -t'title' -c'credits' ] < qrtfile > fbm"
  1881. X
  1882. X#ifndef lint
  1883. Xstatic char *fbmid =
  1884. X    "$FBM qrt2fbm.c <0.91> 07-Apr-89  (C) 1989 by Michael Mauldin$";
  1885. X#endif
  1886. X
  1887. Xmain (argc, argv)
  1888. Xchar *argv[];
  1889. X{ register int j, k, rowlen;
  1890. X  double aspect = 0.56;
  1891. X  int rows, cols, line, len, planes=3;
  1892. X  FBMHDR hdr;
  1893. X  unsigned char *buf;
  1894. X  char title[FBM_MAX_TITLE], credits[FBM_MAX_TITLE];
  1895. X
  1896. X  /* Get the options */
  1897. X  while (--argc > 0 && (*++argv)[0] == '-')
  1898. X  { while (*++(*argv))
  1899. X    { switch (**argv)
  1900. X      { 
  1901. X    case 't':    strncpy (title, *argv+1, FBM_MAX_TITLE);
  1902. X            title[FBM_MAX_TITLE-1] = '\0';
  1903. X            CLRARG; break;
  1904. X    case 'c':    strncpy (credits, *argv+1, FBM_MAX_TITLE);
  1905. X            credits[FBM_MAX_TITLE-1] = '\0';
  1906. X            CLRARG; break;
  1907. X    default:    fprintf (stderr, "%s\n", USAGE);
  1908. X            exit (1);
  1909. X      }
  1910. X    }
  1911. X  }
  1912. X
  1913. X  cols = getchar();
  1914. X  cols |= (getchar()<<8);
  1915. X  rows = getchar();
  1916. X  rows |= (getchar()<<8);
  1917. X  
  1918. X  rowlen = 2 * ((cols * 8 + 15) / 16);
  1919. X
  1920. X  /* Build header */
  1921. X  hdr.rows = rows;
  1922. X  hdr.cols = cols;
  1923. X  hdr.planes = planes;
  1924. X  hdr.bits = 8;
  1925. X  hdr.physbits = 8;
  1926. X  hdr.rowlen = rowlen;
  1927. X  hdr.plnlen = hdr.rowlen * rows;
  1928. X  hdr.clrlen = 0;
  1929. X  hdr.aspect = aspect;
  1930. X  strcpy (hdr.title, title);
  1931. X  strcpy (hdr.credits, credits);
  1932. X  
  1933. X  write_hdr_fbm (&hdr, stdout);
  1934. X  
  1935. X  len = planes*cols; 
  1936. X  buf = (unsigned char *) malloc (rows*len);
  1937. X
  1938. X  for (j=0; j<rows; j++){
  1939. X    line = getchar();
  1940. X    line |= (getchar()<<8);
  1941. X    if (! fread (&buf[j*len], len, 1, stdin))
  1942. X      { fprintf (stderr, "premature end of file on input at line %d\n", line);
  1943. X        break;
  1944. X      }
  1945. X    }
  1946. X
  1947. X  for(k=0; k<planes; k++){
  1948. X    for (j=0; j<rows; j++){
  1949. X      if (! fwrite (&buf[j*len+k*cols], rowlen, 1, stdout))
  1950. X        { perror ("qrt2fbm"); exit (1); }
  1951. X      }
  1952. X    }
  1953. X  
  1954. X  exit (0);
  1955. X}
  1956. END_OF_FILE
  1957. if test 2571 -ne `wc -c <'qrt2fbm.c'`; then
  1958.     echo shar: \"'qrt2fbm.c'\" unpacked with wrong size!
  1959. fi
  1960. # end of 'qrt2fbm.c'
  1961. fi
  1962. echo shar: End of archive 2 \(of 8\).
  1963. cp /dev/null ark2isdone
  1964. MISSING=""
  1965. for I in 1 2 3 4 5 6 7 8 ; do
  1966.     if test ! -f ark${I}isdone ; then
  1967.     MISSING="${MISSING} ${I}"
  1968.     fi
  1969. done
  1970. if test "${MISSING}" = "" ; then
  1971.     echo You have unpacked all 8 archives.
  1972.     rm -f ark[1-9]isdone
  1973. else
  1974.     echo You still need to unpack the following archives:
  1975.     echo "        " ${MISSING}
  1976. fi
  1977. ##  End of shell archive.
  1978. exit 0
  1979.